import { defHttp } from '@/utils/http/axios';
import { ErrorMessageMode } from '#/axios';
import { BaseResponse} from '@/api/base';
import AbsPageQuery from '@/api/model/AbsPageQuery';
import {ContentTypeEnum} from "@/enums/httpEnum";

// 定义接口地址
enum Api {
  /** 获取项目中所有 service 模块 */
  JAVA_SERVICE_MODULE_LIST = '/toolkit/project/java/serviceModuleList',
  /** 获取所有的 Controller */
  CONTROLLER_LIST = '/toolkit/project/controller/list',
  /** 获取所有的领域对象 */
  DOMAIN_LIST = '/toolkit/project/domain/list',
}

// 定义参数类型

export interface ServiceModuleVO {
  serviceName?: String;
  moduleName?: String;
}

export interface ControllerMeta {
  moduleName?: String;
  canonicalName?: String;
  simpleName?: String;
  requestUri?: String;
  description?: String;
  apiMethodMetas?: ApiMethodMeta[];
}

export interface ControllerQuery extends AbsPageQuery{
  module?: String;
  name?: String;
  description?: String;
}

export interface DomainMeta {
  name?: String;
  canonicalName?: String;
  type?: String;
}

export interface DomainMetaQuery extends AbsPageQuery{
  name?: String;
  type?: String;
}

// 定义接口方法: save
// 获取项目中所有 service 模块
export function javaServiceModuleList(mode: ErrorMessageMode = 'message') {
  return defHttp.get<BaseResponse<Array<ServiceModuleVO>>>(
    {
      url: Api.JAVA_SERVICE_MODULE_LIST,
    },
    {
      errorMessageMode: mode,
    },
  );
}

// 获取所有的 Controller
export function controllerList(params: ControllerQuery, mode: ErrorMessageMode = 'message') {
  return defHttp.post<BaseResponse<Array<ControllerMeta>>>(
    {
      url: Api.CONTROLLER_LIST,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// 获取所有的领域对象
export function domainList(params: DomainMetaQuery, mode: ErrorMessageMode = 'message') {
  return defHttp.post<BaseResponse<Array<DomainMeta>>>(
    {
      url: Api.DOMAIN_LIST,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

